//
//  WBLocationManager.m
//  WeatherBar
//
//  Created by Bert on 2024/6/20.
//

#import "WBLocationManager.h"

@implementation WBLocationManager

+(instancetype)sharedManager{
    static WBLocationManager *manager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[WBLocationManager alloc]init];
    });
    return manager;
}
-(instancetype)init{
    if (self = [super init]) {
        self.delegate = self;
        self.desiredAccuracy = kCLLocationAccuracyBest;
        [self requestWhenInUseAuthorization];
//        [self requestAlwaysAuthorization];
        [self startUpdatingLocation];
        
    }
    return self;
}
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
}

- (void)locationManagerDidChangeAuthorization:(CLLocationManager *)manager {
    CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
    self.status = status;
    if (self.refreshLocationStatusBlock) {
        self.refreshLocationStatusBlock(status);
    }
}

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations{
    CLLocation *location = locations[0];
    self.currentLocation = location;
}

@end
